package GoodsService

import (
	"context"
	"errors"
	"gdshop-back-end-go/client-api/app/response/GoodsResp"
)

func GetGoodsModel(ctx context.Context, goodsId int) (*GoodsResp.Details, error) {
	goodsModel := GetGoodsModelRaw(ctx, goodsId)
	if goodsModel == nil {
		return nil, errors.New("找不到goods数据")
	}
	HandleDetails(ctx, goodsModel, true, 0)

	// 获取拼团信息
	tuanInfo := getOneTuanInfoByGoodsId(ctx, goodsId)
	goodsModel.TuanInfo = tuanInfo
	// 如果有拼团，需要重新获取商品 options
	if tuanInfo.TuanId > 0 {
		goodsModel.TuanOptions = GetGoodsOptionsTuanByGoodsId(ctx, tuanInfo.TuanId, goodsId)
	}
	// 获取秒杀信息

	return goodsModel, nil
}
